package com.ruoyi.zhmk.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkCarDevice;
import com.ruoyi.zhmk.service.IZhmkCarDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车牌设备Controller
 * 
 * @author ruoyi
 * @date 2021-06-24
 */
@RestController
@RequestMapping("/zhmk/device")
public class ZhmkCarDeviceController extends BaseController
{
    @Autowired
    private IZhmkCarDeviceService zhmkCarDeviceService;

    /**
     * 查询车牌设备列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhmkCarDevice zhmkCarDevice)
    {
        startPage();
        List<ZhmkCarDevice> list = zhmkCarDeviceService.selectZhmkCarDeviceList(zhmkCarDevice);
        return getDataTable(list);
    }

    /**
     * 导出车牌设备列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:device:export')")
    @Log(title = "车牌设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZhmkCarDevice zhmkCarDevice)
    {
        List<ZhmkCarDevice> list = zhmkCarDeviceService.selectZhmkCarDeviceList(zhmkCarDevice);
        ExcelUtil<ZhmkCarDevice> util = new ExcelUtil<ZhmkCarDevice>(ZhmkCarDevice.class);
        return util.exportExcel(list, "车牌设备数据");
    }

    /**
     * 获取车牌设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhmk:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zhmkCarDeviceService.selectZhmkCarDeviceById(id));
    }

    /**
     * 新增车牌设备
     */
    @PreAuthorize("@ss.hasPermi('zhmk:device:add')")
    @Log(title = "车牌设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhmkCarDevice zhmkCarDevice)
    {
        return toAjax(zhmkCarDeviceService.insertZhmkCarDevice(zhmkCarDevice));
    }

    /**
     * 修改车牌设备
     */
    @PreAuthorize("@ss.hasPermi('zhmk:device:edit')")
    @Log(title = "车牌设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhmkCarDevice zhmkCarDevice)
    {
        return toAjax(zhmkCarDeviceService.updateZhmkCarDevice(zhmkCarDevice));
    }

    /**
     * 删除车牌设备
     */
    @PreAuthorize("@ss.hasPermi('zhmk:device:remove')")
    @Log(title = "车牌设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhmkCarDeviceService.deleteZhmkCarDeviceByIds(ids));
    }

    /**
     * 开门
     * @param id
     * @return
     */
    @ApiOperation("开门")
    @GetMapping("/openDoor/{id}")
    public AjaxResult openDoor(@PathVariable("id") Long id){
        return zhmkCarDeviceService.openDoor(id);
    }

    /**
     * 查询全部车辆识别设备
     * @return
     */
    @ApiOperation("/查询全部车辆设备")
    @GetMapping("/findAll")
    public AjaxResult findAll(){
        return AjaxResult.success(zhmkCarDeviceService.selectZhmkCarDeviceList(new ZhmkCarDevice()));
    }
}
